/*
验证手机号
*/
const isPhoneNum = function(str) {
	return /^1(3|4|5|7|8)\d{9}$/.test(str);
}
/*
随机获取6位数字
*/
const randomNum = function() {
	return ('000000' + Math.floor(Math.random() * 999999)).slice(-6);
}


const getStartTime=function (min) {
    var time = new Date();
    time.setTime(time.getTime()+min*60000);
    var rYear = time.getFullYear();
    var rMonth = time.getMonth() + 1;
    var rDay = time.getDate();
    var rHour = time.getHours();
    var rMinute = time.getMinutes();
    var rSecond = time.getSeconds();
    var nowTime = rYear + '-' + ZeroFilling(rMonth) + '-' + ZeroFilling(rDay) + ' ' + ZeroFilling(rHour) + ':' + ZeroFilling(rMinute) + ':' + ZeroFilling(rSecond);
    return nowTime;

};

/**
 * 获取当前时间
 */
const getNowTime = function() {
	var myDate = new Date;
	var year = myDate.getFullYear(); //获取当前年
	var mon = myDate.getMonth() + 1; //获取当前月
	var date = myDate.getDate(); //获取当前日
	var h = myDate.getHours(); //获取当前小时数(0-23)
	var m = myDate.getMinutes(); //获取当前分钟数(0-59)
	var s = myDate.getSeconds(); //获取当前秒
	// var week = myDate.getDay();
	// var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	// console.log(year, mon, date, weeks[week])
	return (year + "-" + ZeroFilling(mon) + "-" + ZeroFilling(date) + " " + ZeroFilling(h) + ":" + ZeroFilling(m) +
		":" + ZeroFilling(s));
}
/**
 * 获取当前时间
 */
const getNowTimeHMS = function() {
	var myDate = new Date;
	var year = myDate.getFullYear(); //获取当前年
	var mon = myDate.getMonth() + 1; //获取当前月
	var date = myDate.getDate(); //获取当前日
	var h = myDate.getHours(); //获取当前小时数(0-23)
	var m = myDate.getMinutes(); //获取当前分钟数(0-59)
	var s = myDate.getSeconds(); //获取当前秒
	// var week = myDate.getDay();
	// var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	// console.log(year, mon, date, weeks[week])
	var obj = {
		time:(year + "-" + ZeroFilling(mon) + "-" + ZeroFilling(date) + " " + ZeroFilling(h) + ":" + ZeroFilling(m) +
		":" + ZeroFilling(s)),
		h:h*m*s
	} 
	return obj;
}
/**
 * 获下年的今天
 */
const getNextTime = function() {
	var myDate = new Date;
	var year = myDate.getFullYear() + 3; //获取当前年
	var mon = myDate.getMonth() + 1; //获取当前月
	var date = myDate.getDate(); //获取当前日
	var h = myDate.getHours(); //获取当前小时数(0-23)
	var m = myDate.getMinutes(); //获取当前分钟数(0-59)
	var s = myDate.getSeconds(); //获取当前秒
	// var week = myDate.getDay();
	// var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	// console.log(year, mon, date, weeks[week])
	return (year + "-" + ZeroFilling(mon) + "-" + ZeroFilling(date) + " " + ZeroFilling(h) + ":" + ZeroFilling(m) +
		":" + ZeroFilling(s));
}

const ZeroFilling = function(num) {
	if (num < 10) {
		return "0" + num;
	} else {
		return num;
	}
}
export default {
	isPhoneNum,
	randomNum,
	getNowTime,
	getNextTime,
	getNowTimeHMS,
	getStartTime
}
